import {
  reqGetCompanyList,
  reqBatchAddCompany,
  reqEditCompany,
  reqBatchDelCompany,
  reqCheckCompanyCodeIsRepeat,
  reqQueryForNameAndIdAndCode,
} from '@/views/Custom/CompanyMng/api/companyMngApi';
const actions = {
  // 查询全部企业信息
  async getCompanyList({ commit }, params) {
    let result = await reqGetCompanyList(params);
    commit('GETCOMPANYLIST', result.data.companyIPage);
  },
  // 企业信息新增
  async batchAddCompany({ commit }, params) {
    let result = await reqBatchAddCompany(params);
    return result;
  },
  // 企业编辑
  async editCompany({ commit }, params) {
    let result = await reqEditCompany(params);
    return result;
  },
  // 企业删除
  async delCompany({ commit }, params) {
    let result = await reqBatchDelCompany(params);
    return result;
  },
  // 检查企业名称编码是否重复 -- 在添加时
  async checkIsRepeatForCompanyCode({ commit }, params) {
    let result = await reqCheckCompanyCodeIsRepeat(params);
    return result;
  },
  // 查询企业名称、编号、编码
  async queryForNameAndIdAndCode({ commit }) {
    let result = await reqQueryForNameAndIdAndCode();
    commit('QUERYFORNAMEANDIDANDCODE', result.data.companyIdAndNameAndCodeList);
  },
};
const mutations = {
  GETCOMPANYLIST(state, result) {
    state.companyIPage = result;
  },
  // 查询企业名称、编号、编码
  QUERYFORNAMEANDIDANDCODE(state, result) {
    state.companyIdAndNameAndCodeList = result;
  },
};
const state = {
  companyIPage: {},
  companyList: [],
  companyIdAndNameAndCodeList: [],
};
const getters = {
  // 企业分页查询后的包装数据
  companyIPage(state) {
    return state.companyIPage || [];
  },
  // 企业列表
  companyList(state) {
    return state.companyIPage ? state.companyIPage.records || [] : [];
  },
  companyIdAndNameAndCodeList(state) {
    return state.companyIdAndNameAndCodeList || [];
  },
};
export default {
  namespaced: true,
  actions,
  mutations,
  state,
  getters,
};
